package com.example.designpatterns.creational.singleton;

/**
 * @author zuitu@foxmail.com
 * @date 2024/1/18
 * 双重检测，禁止重排
 */
public class DoubleCheckLock {
    private volatile static User singleton;

    private DoubleCheckLock() {
    }

    public static User getSingleton() {
        if (singleton == null) {
            synchronized (DoubleCheckLock.class) {
                if (singleton == null) {
                    singleton = new User();
                }
            }
        }
        return singleton;
    }
}
